package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "作者的相关信息",tags = "作者的相关信息")
@RequestMapping("/api/v1/author")
public class AuthorController {
    @Autowired
    public AuthorService authorService;

    @ApiOperation("根据id查询用户信息")
    @GetMapping("/findByUserId/{id}")
    public ResponseResult findByUserId(@PathVariable Integer id){
        ApAuthor result = authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, id));
        return ResponseResult.okResult(result);
    }

    @ApiOperation("保存作者信息")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor){
        authorService.save(apAuthor);
        return ResponseResult.okResult();
    }
}
